package com.me.customerdemo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.me.customerdemo.dao.ServerMapper;
import com.me.customerdemo.pojo.Server;
import com.me.customerdemo.service.ServerService;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ServerServerImpl implements ServerService {

 @Autowired
    private ServerMapper serverMapper;

    @Override
    public List<Server> selectAll() {
        return serverMapper.selectAll();
    }

    @Override
    public boolean updateById(Server server) {
        return serverMapper.updateById(server)>0? true:false;
    }

    @Override
    public boolean deleteById(int id) {
        return serverMapper.deleteById(id)>0?true:false;
    }

    @Override
    public boolean apply(Server server) {
        return serverMapper.apply(server)>0?true:false;
    }

    @Override
    public PageInfo<Server> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<Server> servers = serverMapper.selectByKeyword(keyword);
        PageInfo<Server> page = new PageInfo<>(servers);
        return page;
    }

    @Override
    public PageInfo<Server> findAll(int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Server> servers = serverMapper.selectAll();
        PageInfo<Server> page = new PageInfo<>(servers);
        return page;
    }

    @Override
    public Server findById(int id) {
        return serverMapper.selectById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean modify(Server server) {
        return serverMapper.updateById(server) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean removeById(int id) {
        return serverMapper.deleteById(id) > 0;
    }


}
